<template>
  <div class="app-container">
    <!-- 添加或修改会员管理对话框 -->
    <el-dialog title="修改收益余额" :visible.sync="visible" width="40%" append-to-body :close-on-click-modal="false" @close="dialogClose">
      <el-row>
        <el-col :span=12>
          <span>用户ID：{{ userId }}</span>
        </el-col>
        <el-col :span=12>
          <span>用户名：{{ userName }}</span>
        </el-col>
      </el-row>
      <el-form ref="form" :model="form" inline>
        <el-form-item label="收益余额">
          <el-input placeholder="请输入内容" type="number" v-model="form.employeeRetain">
            <template slot="prepend">￥</template>
          </el-input>
        </el-form-item>
        <div>注：非特殊情况，请不要随便修改用户收益余额。</div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" type="primary" @click="dialogUpdate">修改</el-button>
        <el-button size="mini" @click="dialogClose">返回修改</el-button>
      </div>
    </el-dialog>

    <!-- 修改收益余额二次弹窗 -->
    <el-dialog title="修改收益余额" :visible.sync="dialogVisible" width="40%" append-to-body :close-on-click-modal="false" @close="dialogVisible = false">
      <div style="text-align: center;font-size: 18px;line-height: 24px;">
        <div>修改收益余额二次确认</div>
        <div>用户：{{ userId }}({{ userName }})</div>
        <div>收益余额修改：<span style="font-weight: bold">￥{{ employeeRetain }}</span>修改成<span style="font-weight: bold">￥{{ form.employeeRetain }}</span></div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" type="primary" @click="handleUpdate">确认修改</el-button>
        <el-button size="mini" @click="dialogVisible = false">返回修改</el-button>
      </div>
    </el-dialog>
  </div>
</template>
  
<script>
import { saveEmployeeMoney } from "@/api/shuiyin/shuiyin";

export default {
  props: {
    userId: {
      type: String,
      default: ''
    },
    userName: {
      type: String,
      default: ''
    },
    employeeRetain: {
      type: Number,
      default: 0
    },
    dialogVisibleFlag: {
      default: false
    }
  },
  data() {
    return {
      visible: false,
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 租户管理表格数据
      tenantList: [], 
      // 查询参数
      queryParams: {
        userId: null,
        pageNum: 1,
        pageSize: 10,
      },
      form: {
        employeeRetain: ''
      },
      dialogVisible: false
    };
  },
  watch: {
    dialogVisibleFlag() {
      this.visible = this.dialogVisibleFlag;
      if (this.visible) {
        this.form.employeeRetain = this.employeeRetain;
      }
    }
  },
  methods: {
    dialogClose() {
      this.$emit("update:dialogVisibleFlag", false)
    },
    // 修改
    dialogUpdate() {
      this.dialogVisible = true;
    },
    // 确认修改
    handleUpdate() {
      const params = {
        userId: this.userId,
        money: this.form.employeeRetain
      }
      saveEmployeeMoney(params).then(response => {
        this.$modal.msgSuccess("修改成功");
        this.dialogVisible = false;
        this.dialogClose();
      })
    },
  }
};
</script>